package cn.tianyigps.tianyigpsmiletask.dao;

import cn.tianyigps.tianyigpspublic.bean.EquipmentModel;
import cn.tianyigps.tianyigpspublic.mongo.dao.BaseDaoImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class EquipmentDaoImpl extends BaseDaoImp<EquipmentModel> implements EquipmentDao {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public List<EquipmentModel> queryEqCMByList(String equipmentId, Date start, Date end) {
        Criteria criteria = Criteria.where("equipmentId").is(equipmentId);
        criteria.and("locateTime").gte(start).lte(end);
        //排序
        Query query = new Query(criteria).with(new Sort(Sort.Direction.ASC, "locateTime"));
        List<EquipmentModel> equipmentCheckModels = mongoTemplate.find(query, EquipmentModel.class, "equipmentCheckModel");

        return equipmentCheckModels;
    }
}
